Check constants in parameters#5256
Conversation
… parameter in a function call
|
You've opened the pull request against the latest branch 2.2.x. PHPStan 2.2 is not going to be released for months. If your code is relevant on 2.1.x and you want it to be released sooner, please rebase your pull request and change its target to 2.1.x. |
|
This pull request has been marked as ready for review. |
VincentLanglet
left a comment
There was a problem hiding this comment.
Pretty cool, I didn't have the time to fully look at it ; you finished it quickly
|
You can still go through it to see if you find something to change |
| // JSON | ||
| // ———————————————————————————————————————————— | ||
|
|
||
| 'json_encode' => [ |
There was a problem hiding this comment.
how was this map generated? is it AI based? is it generated on other metadata (e.g. php8stubs or similar)?
is this something which can/could be typed via phpdoc instead (e.g. in stub files)?
There was a problem hiding this comment.
It’s Claude looking at PHP documentation and some relevant metadata in phpstorm-stubs describing this. The parameter names are proper from php-8-stubs, that’s why it’s behind “named arguments” support in PhpVersions.
Right now it’s only for built-in functions/methods/constants. If we find a use case for PHPDocs we can add it.
| namespace ConstantParameterCheckCallUserFunc; | ||
|
|
||
| // call_user_func with correct constant | ||
| call_user_func('json_encode', [], JSON_PRETTY_PRINT); |
There was a problem hiding this comment.
looking at this, made me think that we could also support splat operator invocations:
There was a problem hiding this comment.
This feature is purely AST based.
|
it seems starting with this PR on 2.2.x a test started failling: https://github.com/phpstan/phpstan-src/actions/runs/23346042957/job/67911556548 |
I prototyped a new pretty useful feature in a couple of hours.
In the end I want this to be gated behind the bleeding edge, but for now it always checks, so we can see the impact on issue-bot and integration tests.
Can you please review this and bring it over the finish line @staabm and @VincentLanglet?
Closes phpstan/phpstan#12850